package com.zhijian.medical.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhijian.medical.entity.po.ExperimentFishHybridOplog;
import com.zhijian.medical.dao.local.FishHybridOplogMapper;
import com.zhijian.medical.enums.ResponseCodeEnum;
import com.zhijian.medical.exception.BusinessException;
import com.zhijian.medical.service.FishHybridOplogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author li xiao dong
 * @since 2022-08-12
 */
@Service
public class FishHybridOplogServiceImpl extends ServiceImpl<FishHybridOplogMapper, ExperimentFishHybridOplog> implements FishHybridOplogService {
    @Autowired
    private FishHybridOplogMapper hybridOplogMapper;

    @Override
    public Boolean deleteByFishId(Long fishId) {
        QueryWrapper<ExperimentFishHybridOplog> experimentFishHybridOplogQueryWrapper = new QueryWrapper<>();
        experimentFishHybridOplogQueryWrapper.eq("fish_id", fishId);
        return hybridOplogMapper.delete(experimentFishHybridOplogQueryWrapper) > 0;
    }

    @Override
    public Boolean insert(ExperimentFishHybridOplog hybridOplog) {
        int count = hybridOplogMapper.insert(hybridOplog);
        if(count<=0){
            throw new BusinessException(ResponseCodeEnum.FAILURE.code, "杂交室创建失败");
        }
        return true;
    }

    @Override
    public List<ExperimentFishHybridOplog> list(Long fishId) {
        QueryWrapper<ExperimentFishHybridOplog> experimentFishHybridOplogQueryWrapper = new QueryWrapper<>();
        experimentFishHybridOplogQueryWrapper.eq("fish_id", fishId);
        return hybridOplogMapper.selectList(experimentFishHybridOplogQueryWrapper);
    }
}
